
 $(function() {	
	// openDB();
	// executeSQL("delete from nxggxb");
	selectNewData();
 });
function createtable(){
	
	var createsql = 'create table if not exists gxb('
	          +'"personid" char(100),'
			  +'"name" char(100),'
			  +'"sex" char(100),'
			  +'"happentime" char(100),'
			  +'"visityType" char(20),'
			  +'"sfbr" char(20),'
			  +'"tgrgx" char(200),'
			  +'"height" char(20),'
			  +'"weight" char(20),'
			  +'"yaowei" char(20),'
			  +'"ywfb" char(20),'
			  +'"fbcs" char(20),'
			  +'"zd" char(100),'
			  +'"zdjg" char(300),'
			  +'"gy" char(20),'
			  +'"dy" char(20),'
			  +'"kzqk" char(20),'
			  +'"sfxf" char(20),'
			  +'"qztime" char(20),'
			  +'"sffy" char(20),'
			  +'"yyqk" char(200),'
			  +'"sfys" char(50)'
	          +')' 
	app.InsertSql(createsql);

	//executeSQL(createsql);//创建表单
}  
function saveInfo(){
	//openDB();
	//createtable();
	var happentime = $("#happentime").val();//随访日期
	var visityType = $("input[name='sffs']:checked").val();//随访方式
	var sfbr = $("input[name='sfbr']:checked").val();//是否本人
	var tgrgx = $("#tgrgx").val();//提供信息者与被访人关系
	var height = $("#height").val();//身高
	var weight = $("#weight").val();//体重
	var yaowei = $("#yaowei").val();//腰围
	var ywfb = $("input[name='xfsj']:checked").val();//是否发病
	var fbcs = $("#fbcs").val();//发病次数
	var zd = $("#zd").val();//诊断
	var zdjg = $("#zdjg").val();//诊断机构
	var gy = $("#gy").val();//血压高压
	var dy = $("#dy").val();//血压低压
	var kzqk = $("input[name='kzqk']:checked").val();//控制情况
	var sfxf = $("input[name='sfgxy']:checked").val();//是否新发现高血压
	var qztime = $("#qztime").val();//确诊时间
	var sffy = $("input[name='sffy']:checked").val();//是否服用降压药
	var yyqk = $("input[name='yyqk']:checked").val();//用药情况
	var sfys = $("#sfys").val();//随访医生
	// alert(visityType);
	var insertsql = "insert into gxb(personid,name,sex,happentime,visityType,sfbr,tgrgx,height,weight,yaowei,ywfb,fbcs,zd,zdjg,gy,dy,kzqk,sfxf,qztime,sffy,yyqk,sfys) values("
					+"'"+personid+"',"
					+"'"+name+"',"
					+"'"+sex+"',"
					+"'"+happentime+"',"
					+"'"+visityType+"',"
					+"'"+sfbr+"',"
					+"'"+tgrgx+"',"
					+"'"+height+"',"
					+"'"+weight+"',"
					+"'"+yaowei+"',"
					+"'"+ywfb+"',"
					+"'"+fbcs+"',"
					+"'"+zd+"',"
					+"'"+zdjg+"',"
					+"'"+gy+"',"
					+"'"+dy+"',"
					+"'"+kzqk+"',"
					+"'"+sfxf+"',"
					+"'"+qztime+"',"
					+"'"+sffy+"',"
					+"'"+yyqk+"',"
					+"'"+sfys+"'"
					+")";
	var jg = app.InsertSql(insertsql);
	if("success"==jg){
	    alert("操作成功！");
	}
	//alert(jg);

	// transactionDB();//开启事务
	// executeSQL(insertsql);
	
	
	// transactionDBcommit();
	// closeDB();
	// selectSQL();
	
}

function selectNewData(){
		var selectsql = 'select * from gxb where personid='+personid+" order by happentime desc";

        var data = app.getInfo(selectsql);
        var obj = eval('(' + data + ')');
//          var list =  JSON.stringify(data);
//               alert(list);
//        alert(obj.length);
//        alert(obj[0]);
//        alert(obj[0].name);
//       alert(list[0].name);
//       alert(list.name);
	//'select * from database'
        if(null!=obj&&obj.length>0){
             var info = obj[0];
           $("#xm").html(info.name);
           $("#xb").html(info.sex);
           $("#happentime").val(info.happentime);//随访日期
           $("input[name='sffs'][value='"+info.visityType+"']").prop("checked",true);//随访方式
           $("input[name='sfbr'][value='"+info.sfbr+"']").prop("checked",true);//是否本人
           $("#tgrgx").val(info.tgrgx);//提供信息者与被访人关系
           $("#height").val(info.height);//身高
           $("#weight").val(info.weight);//体重
           $("#yaowei").val(info.yaowei);//腰围
            $("input[name='xfsj'][value='"+info.ywfb+"']").prop("checked",true);//是否发病
           $("#fbcs").val(info.fbcs);//发病次数
           $("#zd").val(info.zd);//诊断
           $("#zdjg").val(info.zdjg);//诊断机构
           $("#gy").val(info.gy);//高压
           $("#dy").val(info.dy);//低压
           $("input[name='kzqk'][value='"+info.kzqk+"']").prop("checked",true);//控制情况
           $("input[name='sfgxy'][value='"+info.sfxf+"']").prop("checked",true);//是否新发现高血压
           $("#qztime").val(info.qztime);//确诊时间
           $("input[name='sffy'][value='"+info.sffy+"']").prop("checked",true);//是否服用降压药
            $("input[name='yyqk'][value='"+info.yyqk+"']").prop("checked",true);//用药情况
            $("#sfys option[value='"+info.sfys+"']").attr("selected","selected");//随访医生

        }


		
}